package com.hy.thread;

import com.hy.admin.service.CourseService;
import com.hy.admin.service.MessageService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class QueryTranslateThread implements Runnable{
    protected final Logger logBase = LoggerFactory.getLogger(QueryTranslateThread.class);
    CourseService courseService = (CourseService) SpringContextUtil.getBean("courseServiceImpl");

    private String taskId;
    private String uuid;

    public QueryTranslateThread(String taskId, String uuid) {
        this.taskId = taskId;
        this.uuid = uuid;
    }

    @Override
    public void run() {
        logBase.info("query thread:taskId=" + taskId +",uuid=" + uuid);
        if(!StringUtils.isEmpty(uuid) && !StringUtils.isEmpty(taskId)){
            try {
                String status = "RUNNING";
                while("RUNNING".equals(status)) {
                    //如果插入数据失败，5秒后继续插入直到成功为止
                    Thread.sleep(10000);
                    status = courseService.queryTranResult(taskId, uuid);
                    logBase.info("query thread result : " + status);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
